package com.zw.pm.module.overview.statistical;


import com.zw.pm.gen.entity.Project;
import com.zw.pm.gen.entity.ProjectExample;
import com.zw.pm.gen.mapper.ProjectMapper;
import com.zw.pm.module.project.build.ProjectDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.expression.Lists;

import java.util.LinkedList;
import java.util.List;

/**
 * @Description: 统计 服务层
 * @Author: China.sgl
 * @Date: 2019/9/16 09:11
 */
@Service
public class StatisticalService {

    @Autowired
    private ProjectDao projectDao;
    @Autowired
    private ProjectMapper projectMapper;


    /**
     * 根据项目状态返回项目数量
     *
     * @param status 项目状态
     * @return
     */
    public Integer projectCountByStatus(List<Integer> status) {

        Integer allProjectCount = 0;

        ProjectExample ex = new ProjectExample();
        ProjectExample.Criteria criteria = ex.createCriteria();
        criteria.andStatusIn(status);

        List<Project> projects = projectMapper.selectByExample(ex);

        if (projects != null && projects.size() > 0) {
            allProjectCount = projects.size();
        }
        return allProjectCount;
    }

    /**
     * 年查询
     *
     * @param year
     * @param status
     * @return
     */
    public Integer projectCountByYearAndMonthStatus(Integer year, Integer month, String status,Integer orderType) {

        StatisticalModel statisticalModel = new StatisticalModel();

        statisticalModel.setYear(year);
        statisticalModel.setMonth(month);
        statisticalModel.setStatus(status);
        statisticalModel.setOrderType(orderType);
        return projectDao.projectCountByYearAndMonthStatus(statisticalModel);
    }


    /**
     * 年查询
     *
     * @param year
     * @param status
     * @return
     */
    public Integer projectCountByYearAndMonthStatusAndSendTime(Integer year, Integer month, String status,Integer orderType) {

        StatisticalModel statisticalModel = new StatisticalModel();

        statisticalModel.setYear(year);
        statisticalModel.setMonth(month);
        statisticalModel.setStatus(status);
        statisticalModel.setOrderType(orderType);
        return projectDao.projectCountByYearAndMonthStatusAndSendTime(statisticalModel);
    }


    /**
     * 按条件查询没发货项目数量
     * @param year
     * @param month
     * @return
     */
    public Integer noSendProjectCountByYearAndMonth(Integer year, Integer month,Integer orderType) {

        StatisticalModel statisticalModel = new StatisticalModel();

        statisticalModel.setYear(year);
        statisticalModel.setMonth(month);
        statisticalModel.setOrderType(orderType);
        return projectDao.noSendProjectCountByYearAndMonth(statisticalModel);
    }


    /**
     * 图表数据取得
     *
     * @return
     */
    public List<StatisticalModel> barChartData() {

        return projectDao.barChartData();

    }

    /**
     * 取得订单类型项目数量
     *
     * @return
     */
    public List<StatisticalModel> pieChartData() {

        return projectDao.pieChartData();

    }


    public Double getTotalWeightByOrderType(Integer orderType) {
        return projectDao.getTotalWeightByOrderType(orderType);
    }

    public Double getStoreWeightByOrderType(Integer orderType) {
        return projectDao.getStoreWeightByOrderType(orderType);
    }

    public Integer getNoCompleteProjectByOrderType(Integer orderType) {
        return projectDao.getNoCompleteProjectByOrderType(orderType);
    }
}
